package mhys.Dao;

import mhys.Entity.Manage;
import mhys.Util.DBUtil;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ManageDao extends BaseDao{
    public List<Manage> getStuScore(){
        String sql = "SELECT student.s_id,student.s_number,student.s_name,score.object,score.score,score.point FROM student,score WHERE student.s_id = score.s_id";
        List<Manage> manages = new ArrayList<Manage>();
        try {
            res = select(sql);
            while (res.next()){
                Integer s_id = res.getInt("s_id");
                String s_number = res.getString("s_number");
                String s_name = res.getString("s_name");
                String object = res.getString("object");
                Double score = res.getDouble("score");
                Double point = res.getDouble("point");
                Manage manage = new Manage(s_id,s_number,s_name,object,score,point);
                manages.add(manage);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
            DBUtil.close(res,stmt,conn);
        }
        return manages;
    }
    public List<Manage> getStuByName(String name){
        String sql = "SELECT student.s_id,student.s_number,student.s_name,score.object,score.score,score.point FROM student,score WHERE student.s_id = score.s_id and student.s_name like ?";
        List<Manage> manages = new ArrayList<Manage>();
        try {
            res = select(sql,name);
            while (res.next()){
                Integer s_id = res.getInt("s_id");
                String s_number = res.getString("s_number");
                String s_name = res.getString("s_name");
                String object = res.getString("object");
                Double score = res.getDouble("score");
                Double point = res.getDouble("point");
                Manage manage = new Manage(s_id,s_number,s_name,object,score,point);
                manages.add(manage);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }finally {
            DBUtil.close(res,stmt,conn);
        }
        return manages;
    }

//    public static void main(String[] args) {
//        manageDao manageDao = new manageDao();
//        System.out.println(manageDao.getStuScore());
//    }
}
